<?php
namespace app\home\model;
use think\Model;

class WithdrawalsModel extends Model
{
	protected $table  = 'qm_withdrawals';

	//用户-当天已申请提现金额OR提现次数
	public function addMemberTx($member_id, $if_number = '')
	{
		$stime = date('Y-m-d');//起始时间
		$etime = date('Y-m-d', strtotime('+1 day'));//结束时间
		$where = [
			['member_id', '=', $member_id],
			['status', 'in', [1,2]],
			['add_time', '>=', $stime],
			['add_time', '<=', $etime],
		];
		if($if_number == '')
		{
			$money = $this->where($where)->sum('money');
			return $money;
		}else{
			$number = $this->where($where)->count('*');
			return $number;
		}
	}



	//增加提现记录一条
	public function addMemberTxInfo($data)
	{
		$res = $this->insertGetId($data);
		return $res;
	}



	//获取提现100元以下的数据
	public function getMemberTxList()
	{
		$where = [
			['status', '=', 1],
			['money', '<=', 100],
		];
		$list = $this->where($where)->select();
		if(!empty($list))
		{
			$list = $list->toArray();
		}
		return $list;
	}



	/**
	*
	*更新提现状态
	*
	**/
	public function updateMemberTxStatus($where, $update)
	{
		$res = $this->where($where)->update($update);
		return $res;
	}


	/*
	*
	*查看-提现数据
	*
	**/
	public function getMemberTxInfoStatus($where, $field = '*')
	{
		$info = $this->where($where)->field($field)->find();
		return $info;
	}


}